package covertjava.loadtest;

import junit.framework.TestCase;

import covertjava.chat.ChatServer;
import org.apache.log4j.Logger;

/**
 * <p>Implements JUnit test case that sends a message to Chat</p>
 * <p>Copyright: Copyright (c) 2004 Sams Publishing</p>
 * @author Alex Kalinovsky
 * @version 1.0
 */
public class ChatTestCase extends TestCase {
    private String host;
    public static int messagesSent;

    static Logger logger = Logger.getLogger(ChatTestCase.class.getName());


    public ChatTestCase() {
        super("testSendMessage");
    }


    protected void setUp() {
        this.host = System.getProperty("covertjava.loadtest.chat.host", "localhost");
    }


    public void testSendMessage() {
        logger.info("Sending test message...");
        try {
            StringBuffer message = new StringBuffer();
            message.append("[ChatTestCase@");
            message.append(Integer.toHexString(this.hashCode()));
            message.append("] Test ");
            message.append(messagesSent++);
            ChatServer.getInstance().sendMessage(this.host, message.toString());
            logger.info("Sent message successfully");
        }
        catch (Exception e) {
            e.printStackTrace();
            assertTrue("Exception " + e.getClass().getName() + ": " + e.getMessage(), false);
        }
    }
}
